package com.slt.concurrency.mashibing2019.juc.c_004_Volatile.my;

/**
 * volatile  禁止指令重排序
 *
 * DCL ： double check lock
 */
public class Volatile_DCL {
    //构造器私有化 禁止在类外 new对象
    private Volatile_DCL (){}

    private static volatile Volatile_DCL instance;

    private static Volatile_DCL getInstance(){
        //first check
        if(instance == null){
            //其他业务逻辑，锁细化
            synchronized(Volatile_DCL.class){
                //second check
                if(instance == null){
                    instance = new Volatile_DCL();
                }
            }
        }

        return instance;
    }
}
